{*
SPDX-FileCopyrightText: © 2021 Olivier Meunier <olivier@neokraft.net>

SPDX-License-Identifier: AGPL-3.0-only
*}
{{ extends "../profile/base" }}
{{ import "/_libs/forms" }}

{{ block title() }}Users - {{ .User.Username }}{{ end }}

{{ block mainContent() }}
<h1 class="title text-h2">{{ .User.Username }}</h1>

{{- if .User.IsDeleted -}}
  <form action="{{ urlFor(`.`, `delete`) }}" method="POST">
  {{ yield csrfField() }}
  <input type="hidden" name="_to" value="{{ currentPath }}" />
  {{- yield message(type="info") content -}}
    User will be removed in a few seconds&nbsp;
    <button class="btn-primary" name="cancel" value="1">Cancel</button>
  {{- end -}}
</form>
{{- end -}}

<form action="{{ urlFor() }}" method="post">
  {{ yield formErrors(form=.Form) }}
  {{ yield csrfField() }}

  {{ yield textField(field=.Form.Get("username"),
                     required=true,
                     label="Username",
                     class="field-h") }}

  {{ yield textField(field=.Form.Get("email"),
                     type="email",
                     required=true,
                     label="Email address",
                     class="field-h") }}

  {{ yield selectField(field=.Form.Get("group"),
                       label="Group",
                       required=true,
                       class="field-h") }}

  {{ yield passwordField(field=.Form.Get("password"),
                         label="Password",
                         class="field-h",
                         inputAttrs=attrList("autocomplete", "off"),
                         help="will not change if empty") }}

  <p><button class="btn-primary" type="submit">Save</button></p>
</form>

{{- if .User.ID != user.ID && !.User.IsDeleted -}}
  <form class="mt-4" action="{{ urlFor(`.`, `delete`) }}" method="POST">
    {{ yield csrfField() }}
    <p><button class="btn-danger" type="submit">Delete this user</button></p>
  </form>
{{- end -}}

{{ end }}
